<script setup>
import Menu from "@/views/index/Menu.vue";
import Logo from "@/components/Logo.vue";
import {useRoute} from "vue-router";
import {ref, watch, watchEffect} from "vue";
import useBgStore from "@/store/modules/BgStore.js";

const env = import.meta.env
const APP_BASEURL = env.VITE_APP_BASEURL

const route = useRoute()

// 当前路由标题（路由 meta 中的 title）
const title = ref('')
watch(
    () => route.name,
    () => {
      title.value = route.meta.title
    },
    {immediate: true}
)

const bgUrl = ref('')
watchEffect(() => {
  if (useBgStore().bgImgUrl === null || useBgStore().bgImgUrl === undefined || useBgStore().bgImgUrl.length <= 0) {
    bgUrl.value = '/xwb/bookmall/admin/images/bg-default.jpg'
  } else {
    bgUrl.value = useBgStore().bgImgUrl
  }
})
</script>

<template>
  <div class="index w-full h-full">
    <el-container class="w-full">
      <el-aside class="aside" width="auto">
        <Menu></Menu>
      </el-aside>
      <el-container>
        <el-header class="header w-full flex justify-between items-center">
          <div class="title text-gray-100 text-2xl">{{ title }}</div>
          <Logo></Logo>
        </el-header>
        <el-main class="main" :style="{background: `url(${bgUrl}) no-repeat center center`, backgroundSize: 'cover'}">
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<style lang="scss" scoped>
.index {
  .header {
    background-color: #545c64;
  }

  .main {
    width: 100%;
    max-height: calc(100vh - 60px);
    overflow: auto;
  }
}
</style>